<?php

namespace App\Http\Controllers\Admin\Integral;

use App\Http\Controllers\Controller;
use App\Models\LiveAnchor;
use App\Traits\Controllers\AdminTraits;
use App\Transformers\Live\LiveAnchorTransformer;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class LiveAnchorsController extends Controller
{
    use AdminTraits;

    //主持人的模型
    public $model = LiveAnchor::class;

    //主持人的transformer
    public $transformer = LiveAnchorTransformer::class;

    //进行表单验证
    public function rules(Request $request): array
    {
        switch ($request->method()) {
            case 'GET':
                return [];
                break;
            case 'POST':
                return [
                    'name' => 'required|max:50',
                    'wechat' => ['required','unique:live_anchors'],
                    'phone' => ['required', 'regex:/^1[3-9]\d{9}$/','unique:live_anchors']
                ];
                break;
            case 'PATCH':
            case 'PUT':
                return [
                    'name' => 'required|max:50',
                    'wechat' => ['required',Rule::unique('live_anchors', 'wechat')
                        // ignore() 方法去除当前的id字段  route_parameter 的参数为路由中的参数名
                        ->ignore(route_parameter('live_Anchor'), 'id')],
                    'phone' => ['required', 'regex:/^1[3-9]\d{9}$/',Rule::unique('live_anchors', 'phone')
                        // ignore() 方法去除当前的id字段   route_parameter 的参数为路由中的参数名
                        ->ignore(route_parameter('live_Anchor'), 'id')],
                ];
                break;
        }
        return [];
    }

    //自定义错误的信息
    public function ruleMessages(): array
    {
        return [];
    }
}
